#include <Windows.h>

#include <iostream>
#include <vector>

extern "C" __declspec(dllimport) void* alloc_in_mt();
extern "C" __declspec(dllimport) intptr_t get_mt_heap();
std::vector<int> f();

int main()
{
    void* p = alloc_in_mt();             // 内存在 DLL（/MT）中分配
    auto dll_heap = get_mt_heap();       // DLL 的堆句柄
    auto exe_heap = _get_heap_handle();  // EXE 的堆句柄（/MD）

    std::cout << "Address of p\t: " << p << "\n";
    std::cout << "DLL heap\t: " << dll_heap << "\n";
    std::cout << "EXE heap\t: " << exe_heap << "\n";
    std::cout << "Same? " << (dll_heap == exe_heap ? "Yes" : "No") << "\n";

    /// ❌ 危险：在 EXE 中 free(p) → 跨堆释放！
    free(p);  // 崩溃！

    auto vec = f();
    std::cout << vec.size() << std::endl;
    std::cout << vec.data() << std::endl;

    return 0;
}
